<?
/*
 * @since 2012.03.29
 * @author Charles Koh
 * @returns {Register User}
 */

$sponsor_id = $_POST['sponsor_id'];
$name = $_POST['full_name'];
$email = $_POST['email_id']."@".$_POST['email_host'];
$phone_reg = $_POST['phone_reg'];
$phone_num = $_POST['phone_num'];
$country = $_POST['country'];

include "../../server/dbconn.php";
		

		$sql = "select id from id_rand_0 where useable=false limit 1;";
		$result = @mysql_query($sql, $connect);
		$num_match = @mysql_num_rows($result);
		$row = @mysql_fetch_array($result);
		
		$sql = "update id_rand_0 set useable=true where id='{$row[id]}';";
		$result = @mysql_query($sql, $connect);
		
		$sql = "insert into member(id,joinedDate,firstPasswd,name,email,phone_region,phone,country,sponsorID) 
			values('{$row[id]}',
				   '{date(Y-m-d)}',
				   password('1234'),
				   '{$name}',
				   '{$email}',
				   '{$phone_reg}',
				   '{$phone_num}',
				   '{$country}',
				   '{$sponsor_id}')";

		$result = @mysql_query($sql, $connect);
		$num_match = @mysql_num_rows($result);

		if ($result)
		{
			// Success
			echo "<script>top.location=\"/xp/\"</script>";
		} else {
			// Fail
			echo "<script>
					alert('Failed register to Server');
					history.go(-1);
				  </script>";
		}

?>
